﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Bankautomat
{
    public partial class Form1 : Form
    {
        model m_Model;

        public Form1()
        {
            
            m_Model = new model();
            InitializeComponent();
            
        }
        private void ResetForm()
        {
            button3.Visible = false;
            button2.Visible = false;
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox5.Text = "";
            textBox1.Focus();
            textBox1.Visible = true;
            textBox2.Visible = true;
            textBox3.Visible = true;
            textBox4.Visible = true;
            textBox5.Visible = true;
            label1.Visible = true;
            label2.Visible = true;
            button4.Visible = true;
            

        }
        private void button1_Click(object sender, EventArgs e)
        {
            m_Model.logout();
            ResetForm();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (m_Model.number(textBox5.Text + textBox4.Text + textBox3.Text + textBox1.Text, textBox2.Text))
            {
                bool ok = m_Model.login(textBox1.Text, textBox2.Text);

                button3.Visible = ok;
                button2.Visible = ok;

                textBox1.Visible = false;
                textBox2.Visible = false;
                textBox3.Visible = false;
                textBox4.Visible = false;
                textBox5.Visible = false;
                label1.Visible = false;
                label2.Visible = false;
                button4.Visible = false;


                if (!ok)
                {
                    ResetForm();
                }
            }
            else
            {
                MessageBox.Show("Wrong card number!");
                ResetForm();
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            
            Form3 TakeCash = new Form3();
            TakeCash.ShowDialog();
            int amnt = TakeCash.GetAmount();
            if (amnt > 0)
            {
                if(m_Model.takeCash(amnt))
                {
                    Form2 Bye = new Form2();
                    Bye.ShowDialog();
                    ResetForm();
                }
                else
                {
                    MessageBox.Show("Sie haben nicht genug Geld!");
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int a;
            a=m_Model.getBalance();
            string b = a.ToString();
            MessageBox.Show(b);
            
        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {
            if (textBox5.TextLength == 4)
            {
                textBox4.Focus();
            }
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {
            if (textBox4.TextLength == 4)
            {
                textBox3.Focus();
            }
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            if (textBox3.TextLength == 4)
            {
                textBox1.Focus();
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (textBox1.TextLength == 4)
            {
                textBox2.Focus();
            }
        }

      
    }
}
